/**
 * @ Author: hongjiazhun
 * @ Create Time: 2023-03-14 20:25:16
 * @ Modified by: hongjiazhun
 * @ Modified time: 2023-04-01 22:23:20
 * @ Description:公用配置
 */

// 基础请求前缀
export const bsaeUrl = process.env.VUE_APP_BASE_API;

// 转成yyyy-MM-dd
export const formatDate = (time) => {
  const year = time.getFullYear();
  const month = time.getMonth() + 1;
  const date = time.getDate();
  const str = `${year}-${month < 10 ? `0${month}` : month}-${date < 10 ? `0${date}` : date}`;
  return str
}

//获取两日期之间日期列表函数
export const getdiffdate = (stime, etime) => {
  //初始化日期列表，数组
  var diffdate = new Array();
  var i = 0;
  //开始日期小于等于结束日期,并循环
  while (stime <= etime) {
    diffdate[i] = stime;
    //获取开始日期时间戳
    var stime_ts = new Date(stime).getTime();
    //增加一天时间戳后的日期
    var next_date = stime_ts + (24 * 60 * 60 * 1000);
    //拼接年月日，这里的月份会返回（0-11），所以要+1
    var next_dates_y = new Date(next_date).getFullYear() + '-';
    var next_dates_m = (new Date(next_date).getMonth() + 1 < 10) ? '0' + (new Date(next_date).getMonth() + 1) + '-' : (new Date(next_date).getMonth() + 1) + '-';
    var next_dates_d = (new Date(next_date).getDate() < 10) ? '0' + new Date(next_date).getDate() : new Date(next_date).getDate();
    stime = next_dates_y + next_dates_m + next_dates_d;
    //增加数组key
    i++;
  }
  return diffdate;
}